<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: zuti666
  Date: 2020/6/23
  Time: 10:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>backend</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/bootstarp/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/css/index.css" />
    <script src="${pageContext.request.contextPath}/statics/js/jquery.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/statics/bootstarp/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/statics/js/userSetting.js" type="text/javascript" charset="utf-8"></script>
    <!-- 引入bootstrap分页插件 -->
    <script type="text/javascript" src="${pageContext.request.contextPath }/statics/js/bootstrap-paginator.js"></script>

    <script type="text/javascript">function exportExcelAll() {
        var url="${pageContext.request.contextPath }/productType/exportExcel?pageIndex=0";
        window.open(url);
    }

    function exportExcel() {
        var url="${pageContext.request.contextPath }/productType/exportExcel?pageIndex="+${pageSupport.currentPageNo};
        window.open(url);
    }


    function ProductTypeValue(id) {
            $("#modifyTypeId").val(id);
    }


    $(function()
        {


            $("#addProductType").click(function()
            {
                $.ajax(
                    {
                        type : "post",
                        url  : "${pageContext.request.contextPath }/productType/addType",
                        data : {"name" : $("#productTypeName").val() },
                        dataType : "json",
                        success  : function(result)
                        {
                            if (result.responseCode == 1)
                            {
                                // alert(1111111);
                                location.href = "${pageContext.request.contextPath }/productType/toProductType?pageIndex=" + ${pageSupport.currentPageNo};
                            }else
                            {
                                $("#errorMsg").tooptip(
                                    {
                                        // alert(2222222);
                                        title : "error",
                                        placement: "center",
                                        template : "<div class='tooltip errorMsg'>" +  result.message + "</div>",
                                        tigger  : "manual"
                                    }).tooltip("show");
                            }
                        },
                        error : function()
                        {
                            alert("服务器内容错误!");
                        }
                    }
                );
            });


            $("#modifyType").click(function()
            {
                $.ajax(
                    {
                        type : "post",
                        url  : "${pageContext.request.contextPath }/productType/modifyName",
                        data : {
                            "id"   : $("#modifyTypeId").val(),
                            "name" : $("#modifyTypeName").val()
                        },
                        dataType : "json",
                        success : function(result)
                        {
                            if (result.responseCode == 1)
                            {
                                location.href = "${pageContext.request.contextPath }/productType/toProductType?pageIndex=" + ${pageSupport.currentPageNo};
                            }else
                            {
                                $("#errorMsg").tooptip(
                                    {
                                        title : "error",
                                        placement: "center",
                                        template : "<div class='tooltip errorMsg'>" +  result.message + "</div>",
                                        tigger  : "manual"
                                    }).tooltip("show");
                            }
                        }

                    });

            });

        });

    </script>
</head>

<body>
<div class="panel panel-default" id="userSet">
    <div class="panel-heading">
        <h3 class="panel-title">商品类型管理</h3>
    </div>
    <div class="panel-body">
        <input type="button" value="添加商品类型" class="btn btn-primary" id="doAddProTpye">
        <div class="modal fade" tabindex="-1" id="ProductType">
            <!-- 窗口声明 -->
            <div class="modal-dialog modal-lg">
                <!-- 内容声明 -->
                <div class="modal-content">
                    <!-- 头部、主体、脚注 -->
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">添加商品类型信息</h4>
                    </div>
                    <div class="modal-body text-center">
                        <div class="row text-right">
                            <label for="productTypeName" class="col-sm-4 control-label">类型名称：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="productTypeName">
                            </div>
                        </div>
                        <br>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-primary addProductType" id="addProductType" name="addProductType">添加</button>
                        <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <br>
        <br>
        <div class="show-list">
            <form method="post" action="${pageContext.request.contextPath}/productType/toProductType">
            <input type="hidden" name="pageIndex" id="pageIndex" value="1"/>
            <table class="table table-bordered table-hover" style='text-align: center;'>
                <thead>
                <tr class="text-danger">
                    <th class="text-center">编号</th>
                    <th class="text-center">类型名称</th>
                    <th class="text-center">状态</th>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody id="tb">
                  <c:forEach var="type" items="${productTypeList}">
                      <tr>
                      <td>${type.id }</td>
                      <td>${type.name }</td>
                      <td>
                          <c:if test="${type.status eq 1 }">启用</c:if>
                          <c:if test="${type.status eq 0 }">禁用</c:if>
                      </td>
                      <td class="text-center">
                          <!-- 添加  data-value="${type.id }" name="toModifyType" 注意这里有多条数据有修改操作, 所以这里不能用id选择器 选中要"修改"的数据 -->

                          <input type="button" class="btn btn-warning btn-sm doProTypeModify" value="修改"  name="toModifyType" data-value="${type.id }"
                            data-target="#myProductType" onclick="ProductTypeValue('${type.id}')">

                          <c:if test="${type.status eq 1 }">
                              <!-- <input type="button" class="btn btn-danger btn-sm doProTypeDisable" value="禁用"> -->
                              <!-- 将以上的input标签变成a标签 因为input标签不能用问号传参 -->
                              <a type="button" class="btn btn-danger btn-sm doProTypeDisable" href="${pageContext.request.contextPath }/productType/modifyProductTypeStatus?id=${type.id }&status=${type.status}&pageNo=${pageSupport.currentPageNo}"> 禁用 </a>
                          </c:if>

                          <c:if test="${type.status eq 0 }">
                              <!-- 把 class的值 btn-danger  改成   btn-success -->
                              <a type="button" class="btn btn-success btn-sm doProTypeDisable" href="${pageContext.request.contextPath }/productType/modifyProductTypeStatus?id=${type.id }&status=${type.status}&pageNo=${pageSupport.currentPageNo}"> 启用 </a>
                          </c:if>
                      </td>
                      </tr>
                  </c:forEach>
                </tbody>
            </table>

            <input type="hidden" id="totalPageCount" value="${pageSupport.totalPageCount}"/>
            <c:import url="../rollpage.jsp">
                <c:param name="totalCount" value="${pageSupport.totalCount}"/>
                <c:param name="currentPageNo" value="${pageSupport.currentPageNo}"/>
                <c:param name="totalPageCount" value="${pageSupport.totalPageCount}"/>
            </c:import>
            </form>

            <input type="button" value="导出本页数据" class="btn btn-primary" id="excelPage" onclick="exportExcel()">
            <input type="button" value="导出全部数据" class="btn btn-primary" id="excelAll" onclick="exportExcelAll()">
        </div>

        <div class="modal fade" tabindex="-1" id="myProductType">
            <!-- 窗口声明 -->
            <div class="modal-dialog modal-lg">
                <!-- 内容声明 -->
                <div class="modal-content">
                    <!-- 头部、主体、脚注 -->
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">商品修改</h4>
                    </div>
                    <div class="modal-body text-center">
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">编号：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="modifyTypeId" readonly="readonly">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">类型名称</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="modifyTypeName">
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-warning updateProType" id="modifyType">修改</button>
                        <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

</html>
